<script type='text/javascript' src='<?=site_url()?>js/plugins/Meio.Autocomplete.js'></script>
<script type='text/javascript'>
	window.addEvent('domready',function(){
		$('commodity_category').addEvent('change',function(){
			var commodity;
			var category = this.get('value');
			var address = 'http://localhost/bursa-komoditas2/commodities/getcommodityname/'+category;
			var commoditySelElement = $('commodity_commodity');
			var optEl = new Element('option');
			var commodityRequest = new Request.JSON({url:address,onSuccess: function(commodity){
				commoditySelElement.set({'html':''});
				optEl.clone().set({'html': '-Pilih Komoditas-','value': '0'}).inject(commoditySelElement);
				commodity.each(function(item){
					
					var elValue = item.CommodityId;
					var elHTML = item.CommodityName;
					
					optEl.clone().set({'html': elHTML,'value': elValue}).inject(commoditySelElement);
				});
			}}).send({});
		});	
		
		$('province').addEvent('change',function(){
			var commodity;
			var province = this.get('value');
			var address = 'http://localhost/bursa-komoditas2/admins/getregency/'+province;
			var regencySelElement = $('regency');
			var optEl = new Element('option');
			var regencyRequest = new Request.JSON({url:address,onSuccess: function(regency){
				regencySelElement.set({'html':''});
				optEl.clone().set({'html': '-Pilih Kabupaten-','value': '0'}).inject(regencySelElement);
				regency.each(function(item){
					
					var elValue = item.RegencyId;
					var elHTML = item.RegencyName;
					
					optEl.clone().set({'html': elHTML,'value': elValue}).inject(regencySelElement);
				});
			}}).send({});
		});	
		
		$('commodity_commodity').addEvent('change',function(){
			var data = [
				{identifier: 1, value: 'Indonesia'},
				{identifier: 2, value: 'Myanmar'},
				{identifier: 3, value: 'Thailand'}
				];
			
			new Meio.Autocomplete.Select('commodity_type', data, {
				valueField: $('commodity_type_value'),
				valueFilter: function(data){
				return data.identifier;
			},
				filter: {
					type: 'contains',
					path: 'value'
			}
		});	
		});
		
		
			
	});
</script>
<?php
	$attr = array('id' => 'commodities_index');
?>
<?=form_open('commodities/index',$attr)?>	
<table border='0'>
	<colgroup>
		<col style="width:25%;text-align:left;" />
		<col style="width:75%;text-align:left;"  />
	</colgroup>
	<tr>
		<td align='left'>
			<label>Kategori</label>
		</td>
		<td align='left'>
			<select name='commodity_category' id='commodity_category'>
				<option value="0">-Pilih Kategori Komoditas-</option>
				<?php
				foreach($category as $cat)
                {
							if($cat['CategoryId'] == $formvalue['kategori']){
								echo "<option value=".$cat['CategoryId']." selected='selected'>".$cat['CategoryName']."</option>";
							}else{
								echo "<option value=".$cat['CategoryId'].">".$cat['CategoryName']."</option>";
							}
                }
                ?>
			</select>
		</td>
	</tr>
    <tr>
		<td align='left'>
			<label>Komoditi</label>
		</td>
		<td align='left'>
			<select name='commodity_commodity' id='commodity_commodity'>
				<option value="0">-Pilih Komoditas-</option>
            </select>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Jenis Komoditi</label>
		</td>
		<td align='left'>
			<input id='commodity_type' type='text' size='30'><input type='hidden' id='commodity_type_value' />
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Lokasi Gudang </label>
		</td>
		<td align='left'>
			<input id='alamatgudang' type='text' size='30'>
		</td>
	</tr>
	<tr>
		<td>
		</td>
		<td align='left'>
			<label>Provinsi</label>
			<select name='province' id='province'>
				<option value="0">-Pilih Provinsi-</option>
				<?php
				foreach($province as $pro)
                {
					echo "<option value=".$pro['ProvinceId'].">".$pro['ProvinceName']."</option>";
				}
                ?>
			</select>
		</td>
	</tr>
	<tr>
		<td>
		</td>
		<td align='left'>
			<label>Kab./Kota</label>
			<select name='regency' id='regency'>
				<option value="0">-Pilih Kabupaten-</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>
		</td>
		<td align='left'>
			<label>Kode Pos</label>
			<input id='kodepos' type='text' size='20'>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Kualitas</label>
		</td>
		<td align='left'>
			<input id='kualitas' type='text' size='30'>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Kuantitas</label>
		</td>
		<td align='left'>
			<input id='qty' type='text' size='6'>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Satuan</label>
		</td>
		<td align='left'>
			<select name='uom' id='uom'>
				<option value="0">-Pilih Satuan-</option>
				<?php
				$default_UOM = $this->session->userdata['site_parameter'][0]['ParameterName']='DEFAULT_UOM'?$this->session->userdata['site_parameter'][0]['ParameterValue']:'1';
				foreach($uom as $u)
				{ ?>
					<option value='<?=$u['UOMId']?>' <?php if($default_UOM==$u['UOMId']) echo "selected=selected"; else "" ?>><?=$u['UOMName']?></option>
				<?php }
                ?>
			</select>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Tanggal Pengiriman</label>
		</td>
		<td align='left'>
			<input id='alamatgudang' type='text' size='30'>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Harga Dasar</label>
		</td>
		<td align='left'>
			<input id='hargadasar' type='text' size='30'>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Harga Jual</label>
		</td>
		<td align='left'>
			<input id='hargajual' type='text' size='30'>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Kemasan</label>
		</td>
		<td align='left'>
			<input id='kemasan' type='text' size='30'>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Deskripsi (ukuran,bentuk komoditas)</label>
		</td>
		<td align='left'>
			<textarea name='deskripsi' cols='24' rows='4'>
			</textarea>
		</td>
	</tr>
	<tr>
		<td align='left'>
			<label>Foto</label>
		</td>
		<td align='left'>
			<input id='foto' type='text' size='19'>
			<input type='button' value='Unggah'>
		</td>
	</tr>
	<tr>
		<td>
		</td>
		<td align='left'>
			<input id='foto' type='text' size='19'>
			<input type='button' value='Unggah'>
		</td>
	</tr>
	<tr>
		<td>
		</td>
		<td align='left'>
			<input id='foto' type='text' size='19'>
			<input type='button' value='Unggah'>
		</td>
	</tr>
</table>
<?=form_close();?>    
